# Definition for singly-linked list.
class ListNode(object):
    def __init__(self, x):
        self.val = x
        self.next = None

class Solution(object):
    def deleteDuplicates(self, head):
        """
        :type head: ListNode
        :rtype: ListNode
        """
        header = ListNode(None)
        cur = header
        last = header
        while head:
            if head.val==last.val or \
            (head.next and head.next.val==head.val):
                last = head
                head = head.next
            else:
                cur.next = head
                last = head
                head = head.next
                cur = cur.next
                cur.next = None
        return header.next

head = ListNode(1)
head.next = ListNode(1)

head = Solution().deleteDuplicates(head)